package com.lindroy.jetpacknotes.lifecycle.lifecycle_process

import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner

/**
 * @author Lin
 * @date 2021/12/23
 * @function
 */
class ApplicationLifecycleObserver : LifecycleEventObserver {
    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        val lifecycleInfo = when (event) {
            Lifecycle.Event.ON_CREATE -> "App create" //应用程序创建，只会调用一次
            Lifecycle.Event.ON_START -> "App start" //应用位于前台
            Lifecycle.Event.ON_RESUME -> "App Resume"  //应用位于前台
            Lifecycle.Event.ON_PAUSE -> "App pause"    //应用位于后台
            Lifecycle.Event.ON_STOP -> "App stop"      //应用位于后台
            Lifecycle.Event.ON_DESTROY -> "App destroy" //App 进程结束，但 onDestroy 不会调用
            else -> ""
        }
        Log.d("Lifecycle-App", lifecycleInfo)
    }
}